<template>
  <div>
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.blurry" clearable size="small" placeholder="输入任务编码或者名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
      <el-button class="filter-item" size="mini" type="danger" icon="el-icon-delete" @click="delMutexTask">删除互斥</el-button>
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" style="width: 100%;"
              border
              stripe
              @selection-change="selectionLineChangeHandle" :header-cell-style="{ background: 'rgba(52, 125, 225, 0.1)', color: '#404248' }">
      <el-table-column type="selection"/>
      <el-table-column prop="appCode" label="应用编码" />
      <el-table-column prop="taskCode" label="任务编码" />
      <el-table-column prop="taskName" label="任务名称" />
      <el-table-column prop="resNum" label="资源数" />
    </el-table>
    <!--分页组件-->
    <el-pagination
            :total="total"
            :current-page="page + 1"
            style="margin-top: 8px;"
            layout="prev, pager, next, sizes,total"
            @size-change="sizeChange"
            @current-change="pageChange"
            :pager-count="3" prev-text=" " next-text=" "
    />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import mutexApi from '@/api/mutexPool/mutex'
export default {
  mixins: [crud],
  data() {
    return {
      title: 'mutexTaskList',
      sort: ['id,desc'],
      rules: {

      },
      totalElements: 0,
      dataonLineListSelections: [],
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    // 获取数据前设置好接口地址
    beforeInit() {
      this.url = 'api/periodTaskDef/findMutexTaskList'
      return true
    },
    initMutexTaskList(groupCode){
      this.query.groupCode = groupCode;
      this.groupCode = groupCode;
      this.toQuery();
    },
    selectionLineChangeHandle (val) {
      this.dataonLineListSelections = val
    },
    delMutexTask(){
      if(this.dataonLineListSelections.length > 0 ){
        this.$confirm(`确认删除选中的${this.dataonLineListSelections.length}条任务吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let param = {taskList: this.dataonLineListSelections, groupCode: this.groupCode};
          mutexApi.delAdminMutexPool(param).then(()=>{
            this.$notify({  message: '删除成功', type: 'success'});
            this.init();
          }).catch((res) =>{
            this.$notify.error({title: '删除失败', message: res.response.data});
          })
        }).catch(() => {
        })
      }else{
        this.$notify({ title: '警告',  message: '请选择至少一条任务', type: 'warning'});
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
